package com.shchekoldin.server.presenter;

import com.shchekoldin.server.dto.MercurialBranchDto;
import org.codehaus.jackson.annotate.JsonProperty;
import org.swift.common.soap.jira.RemoteIssue;

public class MercurialBranchPresenter {

    @JsonProperty
    private String branchKey;

    @JsonProperty
    private boolean branchKeyValid;

    @JsonProperty
    private BranchStatus branchStatus;

    @JsonProperty
    private String branchLastRevision;

    @JsonProperty
    private String issueSummary;

    @JsonProperty
    private IssueStatus issueStatus;

    @JsonProperty
    private String issueAssignee;

    @JsonProperty
    private String issueReporter;

    // -------------------------------------------------------
    // LOGIC
    // -------------------------------------------------------

    //
    // API
    //

    public MercurialBranchPresenter(MercurialBranchDto branch, RemoteIssue issue) {
        this.branchKey = branch.getKey();
        this.branchKeyValid = branch.isKeyValid();
        this.branchStatus = BranchStatus.parse(branch.getStatus().toUpperCase());
        this.branchLastRevision = branch.getLastRevision();

        if (issue != null) {
            this.issueSummary = issue.getSummary();
            this.issueStatus = IssueStatus.parse(issue.getStatus());
            this.issueAssignee = issue.getAssignee();
            this.issueReporter = issue.getReporter();
        }
    }

}
